cmake_minimum_required(VERSION 3.16)
project(wei-scene LANGUAGES C)

set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)

# 查找依赖包
find_package(PkgConfig REQUIRED)

pkg_check_modules(JANSSON REQUIRED jansson)
pkg_check_modules(LIBCURL REQUIRED libcurl)
# pkg_check_modules(NNG REQUIRED nng)

# 包含目录
include_directories(src)
include_directories(src/core)
include_directories(src/config)
include_directories(src/timer)
include_directories(src/api)
include_directories(src/manager)
include_directories(src/database)
include_directories(src/utils)

# 源文件
set(SOURCES
    src/main.c
    src/core/event_loop.c
    src/core/data_pool.c
    src/config/config_manager.c
    src/config/global_config.c
    src/timer/timer_manager.c
    src/api/api_client.c
    src/api/scene_api.c
    src/manager/system_manager.c
    src/utils/logger.c
    src/database/db_manager.c
    src/database/db_schema.c
    src/scenes/scene_action.c
    src/scenes/scene_manager.c
    src/scenes/scene_types.c
    src/scenes/scene_trigger.c
    src/device/device_manager.c
    src/http/http_server.c
    src/control/control_api.c
    src/utils/cron_parser.c
)

# 头文件
set(HEADERER
    src/core/event_loop.h
    src/core/data_pool.h
    src/core/common.h
    src/config/config_manager.h
    src/config/global_config.h
    src/timer/timer_manager.h
    src/api/api_client.h
    src/api/scene_api.h
    src/manager/system_manager.h
    src/utils/logger.h
    src/database/db_manager.h
    src/database/db_schema.h
    src/scenes/scene_action.h
    src/scenes/scene_manager.h
    src/scenes/scene_types.h
    src/scenes/scene_trigger.h
    src/device/device_manager.h
    src/http/http_server.h
    src/control/control_api.h
    src/utils/cron_parser.h
    # src/config/system_config.json
)

# 创建可执行文件
add_executable(wei-scene ${SOURCES}  ${HEADERER})

# 链接库
target_link_libraries(wei-scene
    ${JANSSON_LIBRARIES}
    ${LIBCURL_LIBRARIES}
    ${NNG_LIBRARIES}
    sqlite3
    m  # 数学库
    pthread  # 线程库
)

# 编译选项
target_compile_options(wei-scene PRIVATE -Wall -Wextra -O2)

# 包含目录
target_include_directories(wei-scene PRIVATE
    ${JANSSON_INCLUDE_DIRS}
    ${LIBCURL_INCLUDE_DIRS}
    ${NNG_INCLUDE_DIRS}
)
